package com.wn.naturalbiorhythms;

import java.text.SimpleDateFormat;

import com.wn.naturalbiorhythms.bean.NaturalValue;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class DetailActivity extends Activity {
	
	public static final String key_nvalue = "nvalue";
	public static final String key_next_nvalue = "next_nvalue";
	
	private String tend_up = "↑";
	private String tend_down = "↓";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.detail);
		
		
		Intent intent = getIntent();
		Bundle data = intent.getExtras();
		
		NaturalValue  nvalue= (NaturalValue)data.getSerializable(key_nvalue);
	    NaturalValue next_nvalue = (NaturalValue)data.getSerializable(key_next_nvalue);
	    
		String tend_physical = "";
		String tend_emotional = "";
		String tend_intellictual = "";
		String tend_intuitive = "";
		if(next_nvalue!=null){
			
			tend_physical = tend_down;
			if(next_nvalue.getPhysical()>=nvalue.getPhysical()){
				tend_physical = tend_up;
			}
			
			tend_emotional = tend_down;
			if(next_nvalue.getEmotional()>=nvalue.getEmotional()){
				tend_emotional = tend_up;
			}
			
			tend_intellictual = tend_down;
			if(next_nvalue.getIntellictual()>=nvalue.getIntellictual()){
				tend_intellictual = tend_up;
			}
			
			tend_intuitive = tend_down;
			if(next_nvalue.getIntuitive()>=nvalue.getIntuitive()){
				tend_intuitive = tend_up;
			}
		}
		
		TextView  tv_calendar =(TextView)findViewById(R.id.textView2_calendar);
		tv_calendar.setText(new SimpleDateFormat("yyyy-MM-dd E").format(nvalue.getCalendar().getTime()));
		
		TextView  tv_tend_physical =(TextView)findViewById(R.id.textView2_tend_Physical);
		TextView  tv_tend_emotional =(TextView)findViewById(R.id.textView4_tend_Emotional);
		TextView  tv_tend_intellictual =(TextView)findViewById(R.id.textView6_tend_Intellictual);
		TextView  tv_tend_intuitive =(TextView)findViewById(R.id.textView8_tend_Intuitive);
		tv_tend_physical.setText(tend_physical);
		tv_tend_emotional.setText(tend_emotional);
		tv_tend_intellictual.setText(tend_intellictual);
		tv_tend_intuitive.setText(tend_intuitive);
		
		TextView  tv_physical =(TextView)findViewById(R.id.textView2_physical);
		tv_physical.setText(nvalue.getPhysical()+"");
		TextView  tv_emotional =(TextView)findViewById(R.id.textView4_emotional);
		tv_emotional.setText(nvalue.getEmotional()+"");
		TextView  tv_intellictual =(TextView)findViewById(R.id.textView6_intellictual);
		tv_intellictual.setText(nvalue.getIntellictual()+"");
		TextView  tv_intuitive =(TextView)findViewById(R.id.textView8_intuitive);
		tv_intuitive.setText(nvalue.getIntuitive()+"");
		TextView  tv_daysLived =(TextView)findViewById(R.id.textView10_days_lived);
		tv_daysLived.setText(nvalue.getDayLived()+"");
		
		TextView  tv_InCycle_physical =(TextView)findViewById(R.id.textView2_InCyclePhysical);
		TextView  tv_InCycle_emotional =(TextView)findViewById(R.id.textView4_InCycleEmotional);
		TextView  tv_InCycle_intellictual =(TextView)findViewById(R.id.textView6_InCycleIntellictual);
		TextView  tv_InCycle_intuitive =(TextView)findViewById(R.id.textView8_InCycleIntuitive);
		
		//体力
		byte tp = nvalue.getTypeInCyclePhysical();
		if(tp == 0){
			tv_InCycle_physical.setText(R.string.DayInCycle_Cycle_text);
		}else if(tp == 1){
			tv_InCycle_physical.setText(String.format(getString(R.string.DayInCycle_Climax_text), nvalue.getDayInCyclePhysical()));
		}else if(tp == 2){
			tv_InCycle_physical.setText(R.string.DayInCycle_Critical_text);
		}else{
			tv_InCycle_physical.setText(String.format(getString(R.string.DayInCycle_Lowtide_text), nvalue.getDayInCyclePhysical()));
		}
		
		//情绪
		byte te = nvalue.getTypeInCycleEmotional();
		if(te == 0){
			tv_InCycle_emotional.setText(R.string.DayInCycle_Cycle_text);
		}else if(te == 1){
			tv_InCycle_emotional.setText(String.format(getString(R.string.DayInCycle_Climax_text), nvalue.getDayInCycleEmotional()));
		}else if(te == 2){
			tv_InCycle_emotional.setText(R.string.DayInCycle_Critical_text);
		}else{
			tv_InCycle_emotional.setText(String.format(getString(R.string.DayInCycle_Lowtide_text), nvalue.getDayInCycleEmotional()));
		}
		
		//智力
		byte ti = nvalue.getTypeInCycleIntellictual();
		if(ti == 0){
			tv_InCycle_intellictual.setText(R.string.DayInCycle_Cycle_text);
		}else if(ti == 1){
			tv_InCycle_intellictual.setText(String.format(getString(R.string.DayInCycle_Climax_text), nvalue.getDayInCycleIntellictual()));
		}else if(ti == 2){
			tv_InCycle_intellictual.setText(R.string.DayInCycle_Critical_text);
		}else{
			tv_InCycle_intellictual.setText(String.format(getString(R.string.DayInCycle_Lowtide_text), nvalue.getDayInCycleIntellictual()));
		}
		
		//直觉
		byte tn = nvalue.getTypeInCycleIntuitive();
		if(tn == 0){
			tv_InCycle_intuitive.setText(R.string.DayInCycle_Cycle_text);
		}else if(tn == 1){
			tv_InCycle_intuitive.setText(String.format(getString(R.string.DayInCycle_Climax_text), nvalue.getDayInCycleIntuitive()));
		}else if(tn == 2){
			tv_InCycle_intuitive.setText(R.string.DayInCycle_Critical_text);
		}else{
			tv_InCycle_intuitive.setText(String.format(getString(R.string.DayInCycle_Lowtide_text), nvalue.getDayInCycleIntuitive()));
		}
		
		NaturalBiorhythmsApplication.addActivity(this);
	}

}
